import "package:flutter/material.dart";

var tagList = ['女装', '男装', '日常吃穿', '便服', '便宜玩偶12134', '玩具', '美妆', '美食', '美食外卖'];

// 换行组件
class UseWrap extends StatelessWidget {
  const UseWrap({super.key});
  @override
  Widget build(BuildContext context) {
    // return TagButton('标签按钮', onPressed: () {});
    // return Padding(
    //   padding: const EdgeInsets.all(10),
    //   child: Wrap(
    //     spacing: 5, //一行元素间的间距
    //     runSpacing: 20, //行间间距
    //     // direction: Axis.vertical, //排列方式（垂直）
    //     alignment: WrapAlignment.spaceEvenly, //行内元素位置
    //     children: tagList.map((e) => TagButton(e, onPressed: () {})).toList(),
    //   ),
    // );

    return ListView(
      padding: const EdgeInsets.all(10),
      children: [
        Row(
          children: [
            Text(
              '热搜',
              style: Theme.of(context).textTheme.bodyLarge,
            )
          ],
        ),
        const Divider(
          color: Color(0xffe4e5ea),
        ),
        Wrap(
          spacing: 10,
          runSpacing: 20,
          children: tagList.map((e) => TagButton(e, onPressed: () {})).toList(),
        ),
        const Divider(
          color: Color(0xffe4e5ea),
        ),
        Row(
          children: [
            Text(
              '历史记录',
              style: Theme.of(context).textTheme.bodyLarge,
            )
          ],
        ),
        const Divider(
          color: Color(0xffe4e5ea),
        ),
        Row(
          children: [
            Text(
              '女装',
              style: Theme.of(context).textTheme.bodyMedium,
            ),
          ],
        ),
        const Divider(
          color: Color(0xffe4e5ea),
        ),
        Row(
          children: [
            Text(
              '便宜玩偶',
              style: Theme.of(context).textTheme.bodyMedium,
            )
          ],
        ),
        Container(
          padding: const EdgeInsets.fromLTRB(30, 10, 30, 10),
          child: Row(
            children: [
              Expanded(
                flex: 1,
                child: OutlinedButton.icon(
                  style: ButtonStyle(
                    foregroundColor: MaterialStateProperty.all(Colors.black),
                    shape: MaterialStateProperty.all(RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(10))),
                  ),
                  icon: const Icon(Icons.delete),
                  label: const Text('清空历史'),
                  onPressed: () {},
                ),
              )
            ],
          ),
        ),
      ],
    );
  }
}

// 标签按钮
class TagButton extends StatelessWidget {
  late String text;
  void Function()? onPressed;
  TagButton(
    this.text, {
    super.key,
    required this.onPressed,
  });
  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 28,
      child: ElevatedButton(
        onPressed: onPressed,
        style: ButtonStyle(
          padding: MaterialStateProperty.all(
              const EdgeInsets.fromLTRB(10, 0, 10, 0)),
          backgroundColor: MaterialStateProperty.all(
              const Color.fromARGB(255, 240, 238, 238)),
          foregroundColor: MaterialStateProperty.all(Colors.black),
        ),
        child: Text(
          text,
          style: const TextStyle(fontSize: 12),
        ),
      ),
    );
  }
}
